using System;
using System.Collections;
using System.Web;

namespace Sedna.Core.Controller.Common
{
	/// <summary>
	/// takes a value from a specified ExecutionContext mapped under the <c>ContextName</c>
	/// and adds it to a URL request string
	/// </summary>
	public class ExecutionContextActionParam : IActionParam
	{

		private string name;
		private string contextName;

		/// <summary>
		/// the name that will be used in the URL
		/// </summary>
		/// <remarks>
		/// this name must be unique within the request, no automatic 
		/// validation is available, hence if duplication occurs a Developer must 
		/// sort the situation out oneselfs
		/// </remarks>
		public string Name
		{
			get { return name; }
			set { name = value; }
		}


		/// <summary>
		/// the name of a value in a specified ExecutionContext
		/// The ContextName designates the exact match (without any context 
		/// prefixes or suffixes, hence if a name of a desier 
		/// value in an ExecutionContext is, e.g., 'mycontainer.myTextBox.text', 
		/// then that very name must be specified)
		/// </summary>
		public string ContextName
		{
			set { contextName = value; }
		}

		public string GetValue(IExecutionContext executionContext)
		{
			object value = executionContext[contextName];
			return value!=null?value.ToString():string.Empty;
		}
	}
}
